"""
拓展：三类不同的测试用例写法
"""
from seleniumbase import BaseCase

# 业务方法分类1
class GooglePage:

    def go_to_google(self, sb):
        sb.open("https://google.com/ncr")

    def do_search(self, sb, search_term):
        sb.type('input[title="Search"]', search_term + "\n")

    def click_search_result(self, sb, content):
        sb.click('a[href*="%s"]' % content)

# 业务方法分类2
class SeleniumBaseGitHubPage:
    def click_seleniumbase_io_link(self, sb):
        link = '#readme article a[href*="seleniumbase.io"]'
        sb.wait_for_element_visible(link)
        sb.js_click(link)
        sb.switch_to_newest_window()

# 业务方法分类3
class SeleniumBaseIOPage:
    def do_search_and_click(self, sb, search_term):
        if sb.is_element_visible('[for="__search"] svg'):
            sb.click('[for="__search"] svg')
        sb.type('form[name="search"] input', search_term)
        sb.click("li.md-search-result__item h1:contains(%s)" % search_term)

# 业务方法分类4
class LoginPage:
    def login_to_swag_labs(self, sb, username):
        sb.open("https://www.saucedemo.com")
        sb.type("#user-name", username)
        sb.type("#password", "secret_sauce")
        sb.click('input[type="submit"]')


# 第一种类型的用例
class MyTests(BaseCase):
    def test_page_objects(self):
        search_term = "SeleniumBase GitHub"
        expected_text = "seleniumbase/SeleniumBase"
        GooglePage().go_to_google(self)
        GooglePage().do_search(self, search_term)
        self.assert_text(expected_text, "#search")
        GooglePage().click_search_result(self, expected_text)
        SeleniumBaseGitHubPage().click_seleniumbase_io_link(self)
        SeleniumBaseIOPage().do_search_and_click(self, "Dashboard")
        self.assert_text("Dashboard", "main h1")

    def test_swag_labs_login(self):
        LoginPage().login_to_swag_labs(self, "standard_user")
        self.assert_element("#inventory_container")
        self.assert_element('div:contains("Sauce Labs Backpack")')


# 第二种类型的用例
class MyTests1:
    def test_swag_labs_login(self, sb):
        LoginPage().login_to_swag_labs(sb, "standard_user")
        sb.assert_element("#inventory_container")
        sb.assert_element('div:contains("Sauce Labs Backpack")')


# 第三种类型的用例
from project_demo_001.远程专家服务.page_objects import HomePage, ResultsPage
class GoogleTests(BaseCase):
    def test_google_dot_com(self):
        self.open("https://google.com/ncr")
        self.type(HomePage.search_box, "github")
        self.assert_element(HomePage.list_box)
        self.assert_element(HomePage.search_button)
        self.assert_element(HomePage.feeling_lucky_button)
        self.click(HomePage.search_button)
        self.assert_text("github.com", ResultsPage.search_results)
        self.assert_element(ResultsPage.images_link)
